package cn.rulian.base.basis.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.ExampleMatcher.StringMatcher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.rulian.base.basis.bo.CommonProperty;
import cn.rulian.base.basis.dao.CommonPropertyDao;
import cn.rulian.base.basis.vo.CommonPropertyVo;
import cn.rulian.base.common.service.BaseService;
import cn.rulian.base.common.vo.Result;

/** 
 * 公共参数
 */
@Service
@Transactional(readOnly = true)
public class CommonPropertyService extends BaseService<CommonProperty>
{

	//private final Logger log = LoggerFactory.getLogger(getClass());
	
	@Autowired
	private CommonPropertyDao dao; 

	@Override
	protected CommonPropertyDao getDao()
	{
		return dao;
	}
	
	/**
	 * 查询
	 */
	public Result query(CommonPropertyVo vo)
	{
		Sort sort = new Sort(Direction.ASC, "code"); //倒序
		Pageable pageable = new PageRequest(vo.getPage()-1,vo.getRows(),sort); //分页查询条件
		
		String system = vo.getSystem();	//系统
		String group = vo.getGroup();	//分组
		String name = vo.getName();	//名称
		
		//创建查询条件数据对象
		CommonProperty tj = new CommonProperty();
		tj.setSystem(system);
		tj.setName(name);
		tj.setGroup(group);
		
		//创建匹配器，即如何使用查询条件
        ExampleMatcher matcher = ExampleMatcher.matching() //构建对象
                .withStringMatcher(StringMatcher.CONTAINING) //改变默认字符串匹配方式：模糊查询
                .withIgnoreCase(true); //改变默认大小写忽略方式：忽略大小写
   
        //创建实例
        Example<CommonProperty> ex = Example.of(tj, matcher); 
        
        //查询
        Page<CommonProperty> page = dao.findAll(ex,pageable);
        
		return Result.getResult(page);
	}
	

	
	
}
